package cn.gyxy.controller;

import cn.gyxy.mapper.GuanliMapper;
import cn.gyxy.pojo.Guanli;
import cn.gyxy.service.LoginService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
//@RequestMapping("/loginbs")
public class LoginController {
    @Autowired
    private GuanliMapper guanliMapper;
    @Autowired
    private LoginService loginService;

    //进入登陆页面
    @RequestMapping("/login")
    public String login() {
        return "login";
    }

    //登陆操作
    @RequestMapping("/loginbs")
    public String loginbs(Guanli guanli, Model model) {
        UsernamePasswordToken token = new UsernamePasswordToken(
                guanli.getUsername(), guanli.getPassword());
        Subject currentUser = SecurityUtils.getSubject();
        System.out.println(currentUser + "-----------" + token);
        currentUser.login(token);
        loginService.loginbs(guanli);
        return "redirect:/lgbs/homepage";
    }
 }
